﻿using System;
using System.IO;
using System.Windows.Forms;

namespace Helper
{
    public partial class MainForm : CCWin.Skin_Mac
    {
        public MainForm()
        {
            InitializeComponent();
            this.Icon = Properties.HelpResource.app;
        }
        private void btn_keyHelper_Click(object sender, EventArgs e)
        {
            this.Hide();
            KeyHelper keyHelperForm = new KeyHelper();
            keyHelperForm.FormClosed += (s, arg) =>
            {
                this.Show();
            };
            keyHelperForm.ShowDialog();
        }

        private void btn_fishingHelper_Click(object sender, EventArgs e)
        {
            this.Hide();
            FishingHelper fishingHelperForm = new FishingHelper();
            fishingHelperForm.FormClosed += (s, arg) =>
            {
                this.Show();
            };
            fishingHelperForm.ShowDialog();
        }
        private void btn_examHelper_Click(object sender, EventArgs e)
        {
            this.Hide();
            ExamHelper examHelper = new ExamHelper();
            examHelper.FormClosed += (s, arg) =>
            {
                this.Show();
            };
            examHelper.ShowDialog();
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            CDD.Destroy();
        }

        private void btn_artistHelper_Click(object sender, EventArgs e)
        {
            this.Hide();
            ArtistHelper artistHelper = new ArtistHelper();
            artistHelper.FormClosed += (s, arg) =>
            {
                this.Show();
            };
            artistHelper.ShowDialog();
        }
        private void btn_GreenwoodHelper_Click(object sender, EventArgs e)
        {
            this.Hide();
            GreenwoodHelper greenwoodHelper = new GreenwoodHelper();
            greenwoodHelper.FormClosed += (s, arg) =>
            {
                this.Show();
            };
            greenwoodHelper.ShowDialog();
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            var path = Application.StartupPath + "\\dll\\x86\\ddx86.dll";
            if (Environment.Is64BitOperatingSystem)
            {
                path = Application.StartupPath + "\\dll\\x64\\ddx64.dll";
            }
            if (!File.Exists(path))
            {
                MessageBox.Show("关键文件缺失，请重新下载！", string.Format("错误"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int ret = CDD.Init(path);
            if (ret < 0)
            {
                MessageBox.Show("初始化失败", string.Format("错误{0}", ret), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                btn_keyHelper.Enabled = true;
                btn_fishingHelper.Enabled = true;
                btn_artistHelper.Enabled = true;
                btn_greenwoodHelper.Enabled = true;
                btn_examHelper.Enabled = true;
            }
            KeyCodeMap.Init();
        }

        private void MainForm_VisibleChanged(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                this.ShowInTaskbar = false;
            }
            else
            {
                this.ShowInTaskbar = true;
            }
        }
    }
}
